@Dean21 I just figured this out myself and am just posting in case someone else has the same issue.
My function where I want the timer now looks like shown below:
QObject::connect(&client, &QMMqttClient::onMessageReceived, [this](const QString &topic, const QByteArray &msg) { ui->Alarm_Triggered_Label->setText("Temperature alarm of PSU triggered, HV output disabled for 5 minutes"); ui->HV_ON_OFF_Button->setEnabled(false); // Use QMetaObject::invokeMethod to execute the code in the main GUI thread QMetaObject::invokeMethod(this, "publishAfterDelay", Qt::QueuedConnection); });And the call to function publishAfterDelay() looks like shown below:
void Widget::publishAfterDelay() { QTimer::singleShot(3000, this, [this]() { client.publishMesage("Alarm_5_min_cooldown_complete", "1"); qDebug() << "timer pinged"; }); }Hope this helps anyone else.